package com.zwz.desgin.builder.model;

import lombok.Data;

/**
 * @Description:
 * @Auther: zwz
 * @Date: 2021-03-04-1:53 下午
 */
@Data
public class Student {
    private String name;

    private int age;

    private int num;

    private String email;


    public static Student.Builder builder() {
        return new Student.Builder();
    }

    public static class Builder {
        private String name;

        private int age;

        private int num;

        private String email;

        public Builder name(String name) {
            this.name = name;
            return this;
        }

        public Builder age(int age) {
            this.age = age;
            return this;
        }

        public Builder num(int num) {
            this.num = num;
            return this;
        }
        public Builder email(String email) {
            this.email = email;
            return this;
        }

        public Student build() {
            // 将builder对象传入到学生构造函数
            return new Student(this);
        }
    }
    // 私有化构造器
    private Student(Builder builder) {
        name = builder.name;
        age = builder.age;
        num = builder.num;
        email = builder.email;
    }
}
